﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackSystem.Entities.Dtos.Channel;
using TrackSystem.Entities.Models;

namespace TrackSystem.IO.Ports
{
    /// <summary>
    /// 端口基础接口
    /// </summary>
    public interface IPortBase
    {
        /// <summary>
        /// 初始化端口
        /// </summary>
        /// <param name="channel">通道参数</param>
        /// <returns></returns>
        bool Initialize(ChannelTable channel);
        /// <summary>
        /// 打开端口
        /// </summary>
        /// <returns></returns>
        bool Open();
        /// <summary>
        /// 关闭端口
        /// </summary>
        /// <returns></returns>
        bool Close();
        /// <summary>
        /// 从端口读取字节
        /// </summary>
        /// <param name="buffer">读取的字节缓存</param>
        /// <returns>返回实际读取到的字节数量</returns>
        int Read(byte[] buffer);
        /// <summary>
        /// 向端口写入字节
        /// </summary>
        /// <param name="buffer">写入的字节缓冲</param>
        /// <returns>返回实际写入的字节数</returns>
        int Write(byte[] buffer);
    }
}
